package com.hulushuju.core.net.http;

import com.hulushuju.core.net.ContentType;
import com.hulushuju.core.net.exception.HttpException;

import java.util.List;
import java.util.Map;

/**
 * @Author: Hanjiafeng
 * @Date: 2019-05-28
 * @Desc: 定义响应头接口, 包括请求状态, 重定向url, 请求头, 页面内容
 */
public interface HttpResponse {

    /**
     * 返回发送请求的时间戳
     *
     * @return 毫秒时间戳
     * @throws HttpException 未设置Response
     */
    long getSendRequestMillis() throws HttpException;

    /**
     * 返回接收到Response的时间戳
     *
     * @return long
     * @throws HttpException 未设置Response
     */
    long getReceivedResponseMillis() throws HttpException;

    /**
     * 获取响应状态
     *
     * @return 响应状态吗
     * @throws HttpException http异常
     */
    int getStatus() throws HttpException;

    /**
     * 重定向url
     *
     * @return url
     * @throws HttpException http异常
     */
    String getRedirectUrl() throws HttpException;

    /**
     * 获取返回内容类型
     *
     * @return 类型
     * @throws HttpException 异常
     */
    ContentType getContentType() throws HttpException;

    /**
     * 获取指定响应头参数
     *
     * @param name 响应头名称
     * @return 响应头参数
     * @throws HttpException http异常
     */
    String getHeader(String name) throws HttpException;

    /**
     * 获取全部响应头
     *
     * @return 全部响应头
     * @throws HttpException http异常
     */
    Map<String, List<String>> getHeaders() throws HttpException;

    /**
     * 获取原始返回内容
     *
     * @param c   类型
     * @param <T> 泛型参数
     * @return 根据Class不同, 返回不同的类型
     * @throws HttpException http异常
     */
    <T> T getContent(Class<T> c) throws HttpException;

    /**
     * 获取压缩后的返回内容
     *
     * @return 压缩后的返回内容
     * @throws HttpException http异常
     */
    String getCompressContent() throws HttpException;
}
